<template>
  <div class="objectiveQuestion-warp" style="position: relative;">
    <div class="floatWrap">
      <!-- <div style="height: 32px;">
        <Checkbox
          v-model="selectAllQuestion"
          style="margin-top:8px; width: 66px;"
          @on-change="handleCheckAllQuestion"
          title="仅选择当前页数据"
          >选择所有</Checkbox
        >
      </div> -->

      <div style="height: 32px;line-height: 32px;margin-left: 15px;flex-shrink: 0;">
        <Checkbox v-model="creatByMeModal" @on-change="searchCreatedByMe">由我创建</Checkbox>
      </div>
      <Cascader
        :data="treeExpClassify"
        v-model="objective.typeCode"
        placeholder="选择知识点"
        @on-change="changeCascader"
        filterable
        style="width:150px;display: inline-block;margin-left:15px;"
        change-on-select
      ></Cascader>
      <Select filterable
        clearable
        v-model="objective.modeCode"
        style="width:150px;margin-left:15px;"
        placeholder="题型"
        @on-change="changePage(1)"
      >
        <Option value="1">单选</Option>
        <Option value="2">多选</Option>
        <Option value="3">判断</Option>
        <Option value="4">填空</Option>
        <!--<Option value="5">简答</Option>-->
      </Select>
      <Select filterable
        clearable
        v-model="objective.difficulty"
        style="width:150px;margin-left:15px;"
        placeholder="难度"
        @on-change="changePage(1)"
      >
        <Option value="simple">简单</Option>
        <!--<Option  value="commonly">一般</Option>-->
        <Option value="medium">中等</Option>
        <Option value="hard">较难</Option>
      </Select>


      <Select filterable
          clearable
          multiple
          v-model="objective.applicationList"
          style="width:150px;margin-left: 15px"
          placeholder="题目用途"
          @on-change="changePage(1)"
      >
        <Option v-for="(label,value) in applist" :value="value" :key="value">{{label}}</Option>
      </Select>
      
      
      <Select filterable
        clearable
        v-model="objective.visibility"
        style="width:150px;margin-left:15px;"
        placeholder="可见范围"
        @on-change="changePage(1)"
      >
        <Option value="public">系统</Option>
        <Option value="share">单位</Option>
        <Option value="private">个人</Option>
      </Select>
      <Input
        v-model.trim="objective.questionname"
        clearable
        placeholder="客观题名称"
        style="width:180px;margin-left: 15px"
        @on-change="changePage(1)"
      />
      
      
            <Button
        type="primary"
         style="margin-left: 15px"
        ghost
        @click="exportObjectiveQuestion()"
        icon="ios-cloud-download-outline"
        >导出客观题</Button
      >
      <Tooltip max-width="200" content="多选题大于4个选项的题目请手动录入">
        <Upload
          ref="upload"
          :action="uploadAction"
          :show-upload-list="false"
          :format="['xlsx']"
          :on-format-error="handleFormatError"
          :on-success="getImageUrl"
          @on-error="uploadError"
          :on-progress="handleProgress"
          :before-upload="handleBeforeUpload"
          :headers="uploadHeader"
          style="margin-left: 15px"
        >
          <Button ghost style="height: 32px;" type="primary" :disabled="uploadList.length > 0">
            <div v-if="uploadList.length == 0">
              <Icon type="ios-cloud-upload-outline"></Icon>
              <span>导入客观题</span>
            </div>
            <div class="demo-upload-list" v-for="item in uploadList">
              <Progress
                v-if="item.showProgress"
                :percent="item.percentage"
                hide-info
                style="width:100px"
              ></Progress>
            </div>
          </Button>
        </Upload>
      </Tooltip>
      <Button
        ghost
        style="height: 32px;margin-left: 15px"
        type="primary"
        icon="ios-download-outline"
        ><a
          href="../../api/new-paper/objective/question/excel-template"
          download=""
          class="downloadUrl"
          >下载导入客观题模板</a
        ></Button
      >
      <Button
        type="primary"
        ghost
        @click="addObjectiveQuestion($event, 'add')"
        class="md-add-jh"
        style="margin-left: 15px"
        ><i class="el-icon-edit"></i>创建</Button
      >
     <!--  <Divider type="vertical" />-->
      <Button
        class="header-btn"
        type="primary"
        ghost
        style="height: 32px;margin-left:15px;"
        @click="refreshObjQuesList()"
        ><i class="el-icon-refresh-right"
      /></Button>
    </div>
    <!-- <div v-show="showDataList"> -->
      <div class="page-content">
        <TableList 
            :data="objectiveList" 
            :columns="objectiveCol"
            :page.sync="objective.page"
            :size.sync="objective.pageSize"
            :total="objectListTotal"
            :loading="tableLoading"
            showSelectTag
            :selectName="(data) => escape2Html(data.description)"
            selectKey="id"
            :selection.sync="selectQuestions" 
            @queryFun="queryObjectQuestionList">
         </TableList>
         
      </div>
      
    <Modal
      v-model="addObjectiveQuestionModal.show"
      :title="addObjectiveQuestionModal.title"
      :loading="addObjectiveQuestionModal.loading"
      :mask-closable="false"
      @on-ok="saveObjectQuestion('objectiveQuestionformValidate')"
      @on-cancel="resetField('objectiveQuestionformValidate')"
      width="600px"
    >
      <Form
        ref="objectiveQuestionformValidate"
        :model="objectiveQuestionformValidate"
        :rules="ruleobjectiveQuestionValidate"
        :label-width="120"
      >
        <FormItem label="题型" prop="modeCode">
          <Select filterable
            v-model="objectiveQuestionformValidate.modeCode"
            placeholder="选择题型"
            @on-change="changeAnswerTxt"
            :disabled="questiontypeDisbaled"
          >
            <Option :value="1">单选</Option>
            <Option :value="2">多选</Option>
            <Option :value="3">判断</Option>
            <Option :value="4">填空</Option>
            <!--<Option :value="5">简答</Option>-->
          </Select>
        </FormItem>
        <FormItem label="名称" prop="description">
          <Input
            v-model.trim="objectiveQuestionformValidate.description"
            placeholder="题目名称长度为1-1000个字符"
            v-if="objectiveQuestionformValidate.modeCode != 4"
            type="textarea"
            :maxlength="1000"
            :rows="4"
          ></Input>
          <div v-else>
            <p
              id="quesContent"
              @input="changeContent"
              @blur="validAnswer('blur')"
              @paste="getIndexAndCurContent"
              placeholder="题目名称长度为1-1000个字符"
              :style="{
                background: addObjectiveQuestionModal.title === '修改客观题' ? 'var(--form-item-border-color)' : '',
                cursor:addObjectiveQuestionModal.title === '修改客观题'? 'not-allowed' : ''
              }"
              :contenteditable="addObjectiveQuestionModal.title === '修改客观题' ? false : true"
            ></p>
            <div v-if="!objectiveQuestionformValidate.id">
              <Button
                @click="insertHtmlAtCaret('')"
                type="primary"
                size="small"
                :disabled="disAddBlank"
                >插入填空区</Button
              >
              <p>
                <small style="color:#f90"
                  ><Icon type="ios-information-circle-outline" />可在光标选中位置插入填空区</small
                >
              </p>
              <p>
                <small style="color:#f90"
                  ><Icon
                    type="ios-information-circle-outline"
                  />每个题目只能插入一个填空区,且填空区内容长度为为1-64个字符</small
                >
              </p>
              <p>
                <small style="color:#f90"
                  ><Icon type="ios-information-circle-outline" />题目名称长度为1-1000个字符</small
                >
              </p>
              <p>
                <small style="color:#ed4014">{{ errorTip4 }}</small>
              </p>
            </div>
          </div>
        </FormItem>
        <FormItem label="知识点" prop="typeCode">
          <Cascader
            :data="treeExpClassify"
            v-model="objectiveQuestionformValidate.typeCode"
          ></Cascader>
        </FormItem>
        <FormItem label="题目难度" prop="difficulty">
          <Select filterable v-model="objectiveQuestionformValidate.difficulty" placeholder="选择题目难度">
            <Option value="simple">简单</Option>
            <!--<Option  value="commonly">一般</Option>-->
            <Option value="medium">中等</Option>
            <Option value="hard">较难</Option>
          </Select>
        </FormItem>

        <!--        0 考试和竞赛，1 练习  ，2 通用；默认 0-->
        <FormItem label="题目用途" prop="application" key="application">
          <RadioGroup v-model="objectiveQuestionformValidate.application">
            <Radio  v-for="(dict,value) in dictEntryList" :label="dict.key" :key="dict.key">{{dict.value}}</Radio>
          </RadioGroup>
        </FormItem>
        
        <FormItem label="可见范围" prop="visibility">
          <RadioGroup v-model="objectiveQuestionformValidate.visibility">
            <!--<Radio label="public">系统</Radio>-->
            <Radio label="share">单位</Radio>
            <Radio label="private">个人</Radio>
          </RadioGroup>
        </FormItem>
        <span
          v-if="preQuestion && objectiveQuestionformValidate.modeCode != 4"
          class="questionclass"
        >
        <QuestionCard
            :question="objectiveQuestionformValidate"
            :bordered="true"
        ></QuestionCard>
        </span>
        <span v-if="!preQuestion && objectiveQuestionformValidate.modeCode != 4">
          <FormItem
            v-for="(item, index) in objectiveQuestionformValidate.answers"
            v-if="
              (objectiveQuestionformValidate.modeCode === 1 ||
                objectiveQuestionformValidate.modeCode === 2) &&
                item.status
            "
            :key="index"
            :label="'[' + filterIndex(index + 1) + ']'"
            :prop="'answers.' + index + '.description'"
            :rules="{ required: true, message: '题目答案不能为空', trigger: 'blur,change' }"
            class="answerForm"
          >
            <Row>
              <Col span="18">
                <Input
                  v-model.trim="item.description"
                  type="textarea"
                  :maxlength="200"
                  :rows="2"
                  placeholder="请输入题目答案"
                  style="margin-bottom:12px"
                />
                <!-- <Input v-model.trim="item.explanation" type="text"  placeholder="请输入题目正确答案" />-->
              </Col>
              <Col span="4" offset="1">
                <span
                  v-if="
                    (objectiveQuestionformValidate.modeCode === 2 ||
                      objectiveQuestionformValidate.modeCode === 1) &&
                      objectiveQuestionformValidate.answers.length > 1
                  "
                  ><Button
                    @click="handleRemove(index)"
                    :disabled="
                      objectiveQuestionformValidate.answers.filter((item) => item.status).length ===
                        1 || addObjectiveQuestionModal.title === '修改客观题'
                    "
                    >删除</Button
                  ></span
                >
                <Radio
                  v-model="item.isRight"
                  v-if="objectiveQuestionformValidate.modeCode === 1"
                  @on-change="singleAnswer(index)"
                  :true-value="1"
                  :false-value="0"
                  :disabled="addObjectiveQuestionModal.title === '修改客观题'"
                  >正确答案</Radio
                >
                <Checkbox
                  v-model="item.isRight"
                  v-if="objectiveQuestionformValidate.modeCode === 2"
                  :true-value="1"
                  :false-value="0"
                  :disabled="addObjectiveQuestionModal.title === '修改客观题'"
                  >正确答案</Checkbox
                >
              </Col>
            </Row>
          </FormItem>
          <template v-if="objectiveQuestionformValidate.answers.length">
            <FormItem
              v-if="objectiveQuestionformValidate.modeCode === 3"
              label="题目答案"
              :prop="'answers[0].isRight'"
              :rules="{
                required: true,
                type: 'number',
                message: '题目答案不能为空',
                trigger: 'blur,change'
              }"
            >
              <RadioGroup v-model="objectiveQuestionformValidate.answers[0].isRight">
                <Radio :label="1" :disabled="addObjectiveQuestionModal.title === '修改客观题'"
                  >正确</Radio
                >
                <Radio :label="0" :disabled="addObjectiveQuestionModal.title === '修改客观题'"
                  >错误</Radio
                >
              </RadioGroup>
            </FormItem>
            <FormItem
              v-if="objectiveQuestionformValidate.modeCode === 5"
              label="题目答案"
              :prop="'answers[0].isRight'"
            >
              <Input
                v-model.trim="objectiveQuestionformValidate.answers[0].description"
                type="textarea"
                :maxlength="200"
                :rows="2"
                placeholder="请输入题目答案"
                style="margin-bottom:12px"
              />
            </FormItem>
          </template>
        </span>
        <FormItem
          style="margin-top:0"
          v-if="
            objectiveQuestionformValidate.modeCode != 4 &&
              objectiveQuestionformValidate.modeCode != 5
          "
        >
          <Button
            type="primary"
            :disabled="disbledAdd || addObjectiveQuestionModal.title === '修改客观题'"
            v-if="
              objectiveQuestionformValidate.modeCode === 2 ||
                objectiveQuestionformValidate.modeCode === 1
            "
            @click="addAnswers"
            >增加</Button
          >
          <Button
            type="primary"
            v-if="objectiveQuestionformValidate.modeCode"
            @click="showQuestion"
            >{{ preTxt }}</Button
          >
        </FormItem>
        <FormItem label="题目解析" prop="explanation">
          <Input
            v-model.trim="objectiveQuestionformValidate.explanation"
            type="textarea"
            :maxlength="1000"
            :rows="4"
            placeholder="解析信息"
          />
        </FormItem>
      </Form>
    </Modal>
    <Modal
      v-model="preQuestionModal"
      :footer-hide="true"
      :width="800"
      title="题目预览"
      :mask-closable="false"
    >
      <QuestionCard
          :question="preQuestionDataObj"
          :bordered="true"
      ></QuestionCard>
    </Modal>
    <ImportObjectiveFailModal
      :data="importResultData"
      :show="showFailModal"
      @on-close="showFailModal = false"
    ></ImportObjectiveFailModal>
  </div>
</template>
<script>
import usally from '@/mixin/usally';
import { experType } from '@/api/dict.js';
import {
  queryObjectiveList,
  delQuestion,
  createQuestion,
  modifyQuestion,
  getQuestionAndAnswer,
  exportQuestions
} from '@/api/question';
import encryption from '@/libs/encryption.js';
import ImportObjectiveFailModal from './components/import-objective-fail-modal.vue';
import { escape2Html, html2Escape,showTimeNotSecond } from '@/libs/utils';
import dictMixin from '@/mixin/dictMixin'
import QuestionCard from '@/components/question-list/question-card.vue'
export default {
  name: 'ObjectiveQues',
  components: { ImportObjectiveFailModal,QuestionCard },
  props: ['show'],
  mixins: [dictMixin,usally],
  data() {
    const typeCodelen = (rule, value, callback) => {
      if (value.length > 5) {
        callback(new Error('最多选择5个知识点'));
      }
      callback();
    };
    let September = sessionStorage.getItem('November');
    September = JSON.parse(encryption.SelfUseDecrypt(September));
    return {
      direct: [],
      treeExpClassify: [],
      creatByMeModal: false,
      USER_ID: September.userId,
      USER_Name: September.nickname,
      isRootDesigner: September.isRootDesigner,
      // 页面设置
      fullHeight: document.documentElement.clientHeight,
      fullWidth: document.documentElement.clientWidth,
      setHei: 'auto',
      preQuestionDataObj: {},
      preQuestionModal: false,
      preQuestion: false,
      disbledAdd: false,
      preTxt: '预览',
      questiontypeDisbaled: false,
      objective: {
        questionname: '',
        page: 1,
        pageSize: 10,
        visibility: ''
      },
      objectListTotal: 0,
      objectiveList: [],
      tableLoading :false,
      objectiveCol: [
        {
            type: 'selection',
            width: 60
        },
        {
            type: 'html',
            title: '客观题名称',
            key: 'description',
            tooltip: true,
            on:{
              click:(data) => {
                this.preQuestionFn(data)
              }
            },
            filter: (description) => {
                return this.escape2Html(description);
            }
        },
        {
            title: '知识点',
            key: 'typeCode',
            tooltip: true,
            filter: (typeCode) => {
                return this.pointFilter(typeCode);
            }
        },
        {
            title: '难度',
            key: 'difficulty',
            align: 'left',
            ellipsis: true,
            filter: (difficulty) => {
                return this.difficultyFilter(difficulty);
            }
        },
        {
            title: '题型',
            key: 'modeCode',
            tooltip: true,
            filter: (modeCode) => {
                return this.questionMode(modeCode);
            }
        },

        {
          title: '题目用途',
          key: 'application',
          minWidth: 60,
          tooltip: true,
          filter: (application) => {
            return this.applist[application];
          }
        },
          
          
        {
            title: '可见范围',
            key: 'visibility',
            tooltip: true,
            filter: (visible) => {
                return this.setVisibility(visible).text;
            },
            setColor: (visible) => {
                return this.setVisibility(visible).color;
            }
        },
        {
            title: '创建者',
            key: 'creatorName',
            tooltip: true
        },
        {
            title: '创建时间',
            key: 'created',
            tooltip: true
        },
        {
            title: '操作',
            width: 140,
            key: 'action',
            opList: [
                {
                    txt: '修改',
                    disabled: (data) => this.setIsClick(data) ? true : false,
                    on:{
                      click: (data,e) => {
                        this.addObjectiveQuestion(data, 'modify');
                      }
                    }
                },
                {
                    txt: '删除',
                    type: 'delete',
                    tooltip: true,
                    title: '你确定要删除吗?',
                    disabled: (data) => this.setIsClick(data) ? true : false,
                    on:{
                      click: (data,e) => {
                        this.deleteQuestion(data.id);
                      }
                    }
                  }
              ]
          }
      ],
      index: 1,
      addObjectiveQuestionModal: {
        show: false,
        title: '创建客观题',
        loading: true
      },
      applist: {
        0: '考试和竞赛',
        1: '练习',
        2: '通用',
        3: '课件习题',
      },
      dictEntryList:[
        {key:2,value:'通用'},
        {key:0,value:'考试和竞赛'},
        {key:1,value:'自测'},
        {key:3,value:'课件习题'}
      ],
      
      
      questionAnswer: '题目答案(单选)',
      objectiveQuestionformValidate: {
        description: '',
        typeCode: [],
        difficulty: '',
        modeCode: '',
        explanation: '',
        application:'0',
        visibility: 'share',
        answers: [
          {
            index: 1,
            answerId: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 0,
            questionId: '',
            status: 1
          }
        ]
      },
      ruleobjectiveQuestionValidate: {
        application: [
          {
            required: true,
            message: '题目用途不能为空',
            trigger: 'change'
          }
        ],
        description: [
          { required: true, max: 1000, message: '名称长度为1—1000个字符', trigger: 'blur,change' }
        ],
        typeCode: [
          {
            required: true,
            message: '知识点不能为空',
            trigger: 'blur,change',
            type: 'array',
            min: 2
          }
        ],
        difficulty: [
          {
            required: true,
            message: '难度不能为空',
            trigger: 'blur,change'
          }
        ],
        modeCode: [
          {
            required: true,
            type: 'number',
            message: '类型不能为空',
            trigger: 'blur,change'
          }
        ],
        visibility: [
          {
            required: true,
            message: '可见范围不能为空',
            trigger: 'blur,change'
          }
        ]
      },
      initQuestionObj: {
        answers: [
          {
            answerId: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 0,
            questionId: ''
          }
        ],
        application:'0',
        visibility: 'share',
        description: '',
        difficulty: '',
        enabled: 1,
        explanation: '',
        modeCode: 0,
        id: '',
        timer: 0,
        typeCode: []
      },
      // 显示
      showDataList: false,
      showDefImg: false,
      quesAnswer4: '',
      errorTip4: '',
      disAddBlank: false,
      //导入客观题
      uploadAction: '/api/new-paper/objective/question/import?importSystem=designer',
      uploadHeader: {
        Authorization: localStorage.token,
        Accept: '*/*'
      },
      uploadList: [],
      uploaderror: false,
      filename: '',
      //导入结果
      importResultData: {},
      showFailModal: false,
      selectAllQuestion: false,
      selectQuestions: []
    };
  },
  computed: {},
  filters: {
    noFilter(val) {
      let str;
      switch (val) {
        case 1:
          str = 'A';
          break;
        case 2:
          str = 'B';
          break;
        case 3:
          str = 'C';
          break;
        case 4:
          str = 'D';
          break;
        case 5:
          str = 'E';
          break;
        case 6:
          str = 'F';
          break;
        case 7:
          str = 'G';
          break;
        case 8:
          str = 'H';
          break;
        case 9:
          str = 'I';
          break;
        case 10:
          str = 'J';
          break;
        case 11:
          str = 'K';
          break;
        case 12:
          str = 'L';
          break;
        default:
          str = '';
          break;
      }
      return str;
    }
  },
  async mounted() {
    // this.setStyle();
    // window.onresize = () => {
    //   this.setStyle();
    // };
    await this.getApplications()// 获取字典中的题目用途
    let {treeData,data} = await this.getDictByName('newDirectionType'); //this.getTypeList().then();
    this.treeExpClassify = treeData;
    this.direct = data;
    this.queryObjectQuestionList();
    
    // this.getAllPoint();
  },
  methods: {
    getApplications(){

      experType('purpose_question').then((res) => {
        if (res.code === 1) {

          let attribute = res.attribute.attribute
          if(attribute && attribute.length>0){
            let dictEntryList = attribute[0].dictEntryList||[]
            if(dictEntryList && dictEntryList.length>0) {
              this.applist = {}
              this.dictEntryList = []
            }

            dictEntryList.forEach((item)=>{
              let key = Number(item.dictid)
             
              this.applist[key] = item.dictname
              this.dictEntryList.push({key:key+"",value:item.dictname})
            })
          }
        }
      })
    },
    isRepeatAnswer() {
      let answers = this.objectiveQuestionformValidate.answers;
      for (let i = 0, length = answers.length; i < length; i++) {
        let description = answers[i].description;
        if (description) {
          for (let j = i + 1; j < length; j++) {
            if (description === answers[j].description) {
              return true;
            }
          }
        }
      }
      return false;
    },
    // 设置样式
    setStyle() {
      window.fullHeight = document.documentElement.clientHeight;
      window.fullWidth = document.documentElement.clientWidth;
      this.fullHeight = window.fullHeight;
      this.fullWidth = window.fullWidth;
      let num = this.fullHeight - 200;
      this.setHei = this.fullHeight - 60 - 75 + 'px';
      this.objective.pageSize = Math.floor(num / 96);
    },
    filterIndex(val) {
      if (this.objectiveQuestionformValidate.modeCode === 3) {
        val = 0;
      }
      let str = '';
      switch (val) {
        case 1:
          str = 'A';
          break;
        case 2:
          str = 'B';
          break;
        case 3:
          str = 'C';
          break;
        case 4:
          str = 'D';
          break;
        case 5:
          str = 'E';
          break;
        case 6:
          str = 'F';
          break;
        case 7:
          str = 'G';
          break;
        case 8:
          str = 'H';
          break;
        case 9:
          str = 'I';
          break;
        case 10:
          str = 'J';
          break;
        case 11:
          str = 'K';
          break;
        case 12:
          str = 'L';
          break;
        default:
          str = '';
          break;
      }
      return str;
    },
    initFormData() {
      this.objectiveQuestionformValidate = {
        description: '',
        typeCode: [],
        difficulty: '',
        modeCode: '',
        explanation: '',
        application:'0',
        visibility: 'share',
        answers: [
          {
            index: 1,
            answerId: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 1,
            questionId: '',
            status: 1
          },
          {
            index: 2,
            answerId: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 2,
            questionId: '',
            status: 1
          },
          {
            index: 3,
            answerId: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 3,
            questionId: '',
            status: 1
          },
          {
            index: 4,
            answerId: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 4,
            questionId: '',
            status: 1
          }
        ]
      };
    },
    searchCreatedByMe(val) {
      this.objective.page = 1;

      // this.iconModelInput = ''
      this.queryObjectQuestionList();
    },

    refreshObjQuesList() {
      this.selectQuestions = [];
      (this.objective = {
        page: 1,
        pageSize: this.objective.pageSize,
        visibility: '',
        typeCode: [],
        modeCode: '',
        difficulty: '',
        visibility: '',
        questionname: ''
      }),
        (this.creatByMeModal = false);
      this.queryObjectQuestionList();
    },
    queryObjectQuestionList() {
      //查询列表
      this.tableLoading = true;
      let _this = this;
      let query = {
        pageIndex: _this.objective.page || 1,
        pageSize: _this.objective.pageSize || 20
      };
      let obj = {
        visibility: _this.objective.visibility || ''
      };
      if (_this.objective.questionname) {
        obj.description = html2Escape(_this.objective.questionname);
      }
      if (_this.objective.typeCode && _this.objective.typeCode.length) {
        obj.typeCode = _this.objective.typeCode[_this.objective.typeCode.length - 1];
      } else {
        obj.typeCode = '';
      }
      if (_this.objective.modeCode) {
        obj.modeCode = _this.objective.modeCode;
      }
      if (_this.objective.difficulty) {
        obj.difficulty = _this.objective.difficulty;
      }
      if (this.creatByMeModal) {
        obj.creator = _this.USER_ID;
        obj.self = 1;
      } else {
        obj.creator = '';
        obj.self = 0;
      }
      
      if(this.objective.applicationList && this.objective.applicationList.length>0){
        obj.applicationList = this.objective.applicationList.map(item=>{
          return Number(item)
        })
      }
      
      
      queryObjectiveList(obj, query).then((data) => {
        if (data.code === 1 && data.data.items && data.data.items.length > 0) {
          this.objectiveList = data.data.items;
          this.objectListTotal = data.data.total;
        } else {
          this.objectiveList = [];
          this.objectListTotal = 0;
        }
        this.tableLoading = false;
      }).catch(error => {
        this.tableLoading = false;
      });
    },
    changePage(val) {
      this.objective.page = val;
      this.queryObjectQuestionList();
    },
    changeCascader(value) {
      this.objective.typeCode = value;
      this.changePage(1);
    },
    changeSize(val) {
      this.objective.pageSize = val;
      this.queryObjectQuestionList();
    },
    getAllPoint() {
      experType().then((res) => {
        if (res.code == 1) {
          let attribute = res.attribute.attribute;
          this.direct = attribute[0].dictEntryList;
          let treeExpClassify = {};
          attribute[0].dictEntryList.forEach((dict) => {
            if (dict.parentid) {
              //二级
              if (!treeExpClassify[dict.parentid]) return;
              treeExpClassify[dict.parentid].children.push({
                value: dict.dictid,
                label: dict.dictname
              });
            } else if (!treeExpClassify[dict.dictid] && !dict.parentid) {
              //一级
              treeExpClassify[dict.dictid] = {
                value: dict.dictid,
                label: dict.dictname,
                children: []
              };
            }
          });
          this.treeExpClassify = Object.values(treeExpClassify);
        }
      });
    },
    deleteQuestion(id) {
      let _this = this;
      delQuestion(id).then((data) => {
        if (data.code === 1) {
          _this.$Message.info('删除成功');
          this.objective.page =
            this.objectiveList.length == 1 && this.objective.page > 1
              ? this.objective.page - 1
              : this.objective.page;
          _this.queryObjectQuestionList();
          let index = this.selectQuestions.findIndex((item) => item.id === id);
          if (index !== -1) {
            this.selectQuestions.splice(index, 1);
          }
        } else {
          _this.$Message.error(data.message);
        }
      });
    },
    escape2Html(str, needReplace) {
      if(!str){
        return 
      }
      let repStr = str.replace(/\{\{.*?\}\}/g, '___');
      if (needReplace) {
        return escape2Html(repStr);
      } else {
        return repStr;
      }
    },
    async addObjectiveQuestion(obj, type) {
      //点击创建或者修改按钮的回调
      let _this = this;
      let {treeData,data} = await _this.getDictByName('newDirectionType');
      _this.treeExpClassify = treeData;
      _this.direct = data;
      _this.preQuestion = false;
      _this.preTxt = '预览';
      _this.disbledAdd = false;
      _this.disAddBlank = false;
      _this.errorTip4 = '';
      _this.questiontypeDisbaled = false;
      _this.addObjectiveQuestionModal.show = true;
      _this.resetField('objectiveQuestionformValidate');
      if (type === 'add') {
        _this.addObjectiveQuestionModal.title = '创建客观题';
        _this.initFormData();
        _this.index = 1;
      } else {
        _this.addObjectiveQuestionModal.title = `修改客观题`;
        _this.questiontypeDisbaled = true;
        getQuestionAndAnswer(obj.id).then((data) => {
          if (data.code === 1) {
            obj.difficulty = obj.difficulty.toLowerCase();
            Object.assign(_this.objectiveQuestionformValidate, obj, {
              typeCode: obj.typeCode.split(',')
            });
            _this.objectiveQuestionformValidate.application +=''
            _this.objectiveQuestionformValidate.answers = data.data.answers;
            _this.objectiveQuestionformValidate.answers.sort(function(a, b) {
              return a.no > b.no ? 1 : -1;
            });
            if (_this.objectiveQuestionformValidate.modeCode != 4) {
              _this.objectiveQuestionformValidate.answers = data.data.answers.map((item) => {
                if (item.description.indexOf('】') == 2 || item.description.indexOf(']') == 2) {
                  item.description = this.escape2Html(item.description.slice(3), true);
                }
                item.status = 1;
                return item;
              });
              _this.objectiveQuestionformValidate.description = _this.escape2Html(
                _this.objectiveQuestionformValidate.description,
                true
              );
              _this.objectiveQuestionformValidate.explanation = _this.escape2Html(
                _this.objectiveQuestionformValidate.explanation,
                true
              );
            } else {
              _this.objectiveQuestionformValidate.answers = data.data.answers.map((item) => {
                item.status = 1;
                return item;
              });
              _this.objectiveQuestionformValidate.explanation = _this.escape2Html(
                _this.objectiveQuestionformValidate.explanation,
                true
              );
              setTimeout(() => {
                let contentEle = document.getElementById('quesContent');
                let description = obj.description;
                let answer1 = 1;
                description = description.replace(
                  /\{\{.*?\}\}/g,
                  `<input class='quesBlank' disabled style='width:40px;padding:0px 5px;outline:none;box-shadow:none;border:none;border-bottom:1px solid rgb(168,166,200)'>`
                );
                //								description = description.replace(/\{\{/g,`<input class='quesBlank' style='outline:none;box-shadow:none;border:none;border-bottom:1px solid rgb(168,166,200)'>{{`).replace(/\}\}/g,`}}</input>`);
                contentEle.innerHTML = description;
                contentEle = document.getElementById('quesContent');
                let answersEle = contentEle.getElementsByClassName('quesBlank');
                for (let index in answersEle) {
                  let ele = answersEle[index];
                  if (ele && ele.className == 'quesBlank') {
                    ele.value = _this.escape2Html(
                      _this.objectiveQuestionformValidate.answers[Number(index)].explanation,
                      true
                    );
                  }
                }
                
                console.log('当前题目的所有内容啊啊啊啊啊-------------',this.objectiveQuestionformValidate)
                
                this.changeContent();
              });
            }
          }
        });
      }
    },
    Trim(str, is_global) {
      var result;
      result = str.replace(/(^\s+)|(\s+$)/g, '');
      if (is_global && is_global.toLowerCase() == 'g') {
        result = result.replace(/\s/g, '');
      }
      return result;
    },
    saveObjectQuestion(name) {
      if (
        this.isRepeatAnswer() &&
        (this.objectiveQuestionformValidate.modeCode === 1 ||
          this.objectiveQuestionformValidate.modeCode === 2)
      ) {
        this.$Message.warning('答案不能重复');
        this.cancelLoading('addObjectiveQuestionModal');
        return;
      }
      let _this = this;
      let obj = {};
      let contentEle = document.getElementById('quesContent');
      _this.$refs[name].validate((valid) => {
        if (valid) {
          if (_this.objectiveQuestionformValidate.modeCode == 4) {
            this.validAnswer('blur');
            if (this.errorTip4) {
              _this.cancelLoading('addObjectiveQuestionModal');
              return;
            }
            Object.assign(obj, _this.initQuestionObj, _this.objectiveQuestionformValidate);
            let cloneNode = contentEle.cloneNode(true);
            let answersEle = cloneNode.getElementsByClassName('quesBlank');
            let answers = Array.from(answersEle).map((ele, index) => {
              let answer = {
                answerId: obj.id ? obj.answers[index].answerId : '',
                description: '',
                enabled: 1,
                explanation: html2Escape(this.Trim(ele.value)),
                isRight: 1,
                no: index + 1,
                userAnswer: '',
                questionId: obj.id
              };
              answersEle[index].innerHTML = '{{answer' + (index + 1) + '}}';
              return answer;
            });
            obj.answers = answers;
            obj.description = html2Escape(this.Trim(cloneNode.innerText, ':g'));
            obj.explanation = html2Escape(obj.explanation);
          } else {
            Object.assign(obj, _this.initQuestionObj, _this.objectiveQuestionformValidate);
            if (obj.answers.every((answer) => !answer.isRight) && obj.modeCode == '1') {
              this.$Message.error('请选择1个正确答案!');
              _this.cancelLoading('addObjectiveQuestionModal');
              return;
            } else if (
              obj.answers.filter((answer) => answer.isRight).length < 2 &&
              obj.modeCode == '2'
            ) {
              this.$Message.error('请至少选择2个正确答案!');
              _this.cancelLoading('addObjectiveQuestionModal');
              return;
            }
            obj.description = html2Escape(obj.description);
            obj.explanation = html2Escape(obj.explanation);
            if (obj.modeCode === 3) {
              obj.answers = obj.answers.slice(0, 1);
              obj.answers[0].description = '';
            } else if (obj.modeCode === 5) {
              obj.answers = obj.answers.slice(0, 1);
              obj.answers[0].isRight = 1;
            }
          }
          let copyObj = JSON.parse(JSON.stringify(obj));
          if (copyObj.modeCode === 1 || copyObj.modeCode === 2) {
            // 单选多选，需要把选项的内容格式化
            copyObj.answers.forEach((answer, index) => {
              answer.no = index + 1;
              answer.description = answer.description;
            });
          }
          copyObj.typeCode = copyObj.typeCode.join(',');
          if (_this.addObjectiveQuestionModal.title === '创建客观题') {
            createQuestion(copyObj).then((data) => {
              if (data.code === 1) {
                _this.$Message.info('增加题目成功！');
                //_this.queryObjectQuestionList();
                _this.refreshObjQuesList();
                _this.addObjectiveQuestionModal.show = false;
                if (contentEle) {
                  contentEle.innerHTML = '';
                }
              } else {
                _this.$Message.error(data.message);
                _this.cancelLoading('addObjectiveQuestionModal');
                _this.objectiveQuestionformValidate.answers.forEach(
                  (item) => (item.description = item.description.slice(3))
                ); //返回错误信息的时候保持选项内容的格式
              }
            });
          } else {
            modifyQuestion(copyObj, copyObj.id).then((data) => {
              if (data.code === 1) {
                _this.$Message.info('修改题目成功！');
                _this.queryObjectQuestionList();
                _this.addObjectiveQuestionModal.show = false;
              } else {
                _this.cancelLoading('addObjectiveQuestionModal');
                _this.$Message.error(data.message);
                _this.objectiveQuestionformValidate.answers.forEach(
                  (item) => (item.description = item.description.slice(3))
                ); //返回错误信息的时候保持选项内容的格式
              }
            });
          }
        } else {
          if (_this.objectiveQuestionformValidate.modeCode == 4) {
            _this.validAnswer('blur');
          }
          _this.cancelLoading('addObjectiveQuestionModal');
          _this.$Message.error('表单输入有误，请仔细检查是否有必填项没有输入!');
        }
      });
    },
    cancelLoading(name) {
      this[name].loading = false;
      setTimeout(() => {
        this[name].loading = true;
      });
    },
    resetField(name) {
      this.$refs[name].resetFields();
    },
    addAnswers() {
      this.index++;
      this.objectiveQuestionformValidate.answers.push({
        description: '',
        explanation: '',
        index: this.index,
        status: 1,
        isRight: 0,
        answerId: '',
        no: 0,
        enabled: 1,
        questionId: this.objectiveQuestionformValidate.id || ''
      });
    },
    handleRemove(index) {
      this.objectiveQuestionformValidate.answers[index].status = 0;
      this.objectiveQuestionformValidate.answers.splice(index, 1);
      this.index--;
      this.objectiveQuestionformValidate.answers.forEach((item, index) => {
        item.index = index + 1;
      });
    },
    removeFormErrorTip(filed) {
      this.$refs['objectiveQuestionformValidate'].fields.forEach(function(e) {
        if (e.prop == filed) {
          //这个条件限制可以去掉就是全部重置了
          e.resetField();
        }
      });
    },
    changeAnswerTxt(val) {
      if (val == 4) {
        this.removeFormErrorTip('description');
      }
      this.preQuestion = false;
      this.preTxt = '预览';
      this.disbledAdd = false;
      this.objectiveQuestionformValidate.answers = [
        {
          index: 1,
          answerId: '',
          description: '',
          enabled: 1,
          explanation: '',
          isRight: 0,
          no: 1,
          questionId: '',
          status: 1
        },
        {
          index: 2,
          answerId: '',
          description: '',
          enabled: 1,
          explanation: '',
          isRight: 0,
          no: 2,
          questionId: '',
          status: 1
        },
        {
          index: 3,
          answerId: '',
          description: '',
          enabled: 1,
          explanation: '',
          isRight: 0,
          no: 3,
          questionId: '',
          status: 1
        },
        {
          index: 4,
          answerId: '',
          description: '',
          enabled: 1,
          explanation: '',
          isRight: 0,
          no: 4,
          questionId: '',
          status: 1
        }
      ];
      // if(val===3){
      //   this.preQuestion = false;
      // }
    },
    singleAnswer(val) {
      this.objectiveQuestionformValidate.answers.forEach((item) => {
        item.isRight = 0;
      });
      this.objectiveQuestionformValidate.answers[val].isRight = 1;
    },
    showQuestion() {
      if (!this.objectiveQuestionformValidate.description) {
        this.$Message.info('请输入题目名称');
        return false;
      }
      this.$refs.objectiveQuestionformValidate.validate((valid) => {
        if (valid) {
          if (this.objectiveQuestionformValidate.modeCode != 3) {
            if (
              this.objectiveQuestionformValidate.answers.every(
                (item) => item.isRight == '' || item.isRight == 0
              )
            ) {
              this.$Message.info('请输入正确选项');
              return false;
            }
          }
          if (this.preQuestion) {
            this.preTxt = '预览';
            this.disbledAdd = false;
          } else {
            this.preTxt = '返回';
            this.disbledAdd = true;
          }
          this.preQuestion = !this.preQuestion;
        } else {
          this.cancelLoading('addObjectiveQuestionModal');
          this.$Message.error('表单输入有误，请仔细检查是否有必填项没有输入!');
        }
      });
    },
    preQuestionFn(obj) {
      //点击题目获取详细信息的回调
      // let params = {
      // 	chaId: obj.id,
      // 	type: obj.modeCode == 4 ? 5 : obj.modeCode
      // }
      getQuestionAndAnswer(obj.id)
        .then((data) => {
          if (data.code === 1) {
            this.preQuestionModal = true;
            data.data.answers.forEach((answer) => {
              if (answer.description.indexOf('】') == 2 || answer.description.indexOf(']') == 2) {
                answer.description = answer.description.slice(3);
              }
            });
            data.data.answers.sort(function(a, b) {
              //修正返回数据的顺序,点击详情正常展示
              return a.no > b.no ? 1 : -1;
            });
            this.preQuestionDataObj = data.data;
            //this.sortQuestionAnswer(this.preQuestionDataObj.answers);
          } else {
            this.$Message.error(data.message);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 按钮点击状态
    setReBtnStatus(params) {
      let userid = params.creator;
      if (userid === this.USER_ID || this.isRootDesigner) {
        return false;
      } else {
        return true;
      }
    },
    // 计算index
    handleProIndex(key) {
      return (this.objective.page - 1) * this.objective.pageSize + key + 1;
    },
    pointFilter(code, obj) {
      if(!code){
        return
      }
      let arr1 = this.direct;
      let arr2 = code.split(',');
      let str1 = '';
      let str2 = '';
      arr1.forEach((items) => {
        if (items.dictid === arr2[0]) {
          str1 = items.dictname;
        }
        if (items.dictid === arr2[1] && items.parentid === arr2[0]) {
          str2 = items.dictname;
        }
      });
      return `${str1} / ${str2}`;
    },
    difficultyFilter: (val) => {
      let difficultyStr = '';
      if (val) {
        val = val.toLowerCase();
      }
      switch (val) {
        case 'simple':
          difficultyStr = '简单';
          break;
        case 'commonly':
          difficultyStr = '一般';
          break;
        case 'medium':
          difficultyStr = '中等';
          break;
        case 'hard':
          difficultyStr = '较难';
          break;
      }
      return difficultyStr;
    },
    questionMode(type) {
      //1--单选  2--多选 3---判断
      let status = '';
      switch (type) {
        case 1:
          status = '单选';
          break;
        case 2:
          status = '多选';
          break;
        case 3:
          status = '判断';
          break;
        case 4:
          status = '填空';
          break;
        case 5:
          status = '简答';
          break;
        default:
          status = '暂无';
          break;
      }
      return status;
    },
    // 设置可见范围
    setVisibility(val) {
      let obj = {};
      let text = '';
      let color = '';
      if (val === 'share') {
        text = '单位';
        color = '#32CD32';
      } else if (val === 'private') {
        text = '个人';
        color = '#FFA500';
      } else if (val === 'public') {
        text = '系统';
        color = '#4169E1';
      }
      obj.text = text;
      obj.color = color;
      return obj;
    },
    // 设置知否可点击
    setIsClick(item) {
      if (item.visibility === 'public' || (item.creator !== this.USER_ID && !this.isRootDesigner)) {
        return {
          'pointer-events': 'none'
        };
      }
    },
    setImgSrc(item) {
      if (item.visibility === 'public' || (item.creator !== this.USER_ID && !this.isRootDesigner)) {
        return require('../../../assets/project/modifys.png');
      } else {
        return require('../../../assets/project/modifys-h.png');
      }
    },
    setDelImgSrc(item) {
      if (item.visibility === 'public' || (item.creator !== this.USER_ID && !this.isRootDesigner)) {
        return require('../../../assets/project/delNote-d.png');
      } else {
        return require('../../../assets/project/delNote-h.png');
      }
    },
    insertBlankSpace() {
      var sel, range;
      var textContent;
      sel = window.getSelection();
      range = sel.getRangeAt(0);
      range.deleteContents();
      //				this.getCaretPosition();
    },
    changeContent(e) {
      //输入框长度对文本变化
      let contentEle = document.getElementById('quesContent');
      let answersEle = contentEle.getElementsByClassName('quesBlank');
      if (answersEle.length > 0) {
        this.disAddBlank = true;
      } else {
        this.disAddBlank = false;
      }
      Array.from(answersEle).forEach((ele, index) => {
        let text_length = 0;
        let str = ele.value;
        for (let i = 0; i < str.length; i++) {
          if (str.charCodeAt(i) > 127 || str.charCodeAt(i) == 94) {
            text_length += 2;
          } else {
            text_length++;
          }
        }
        let current_width = Math.ceil(text_length * 7.5) + 10;
        ele.style.width =
          current_width < 40 ? 40 : current_width > 400 ? 400 : current_width + 'px';
      });
      this.validAnswer('blur');
      //判断内容长度大于1-小于128
      //				if(contentEle.innerText.length){
      this.objectiveQuestionformValidate.description = contentEle.innerText;
      //				}
    },
    getIndexAndCurContent(e) {
      console.log(e);
      e.preventDefault();
      let _this = this;
      if (!(e.clipboardData && e.clipboardData.items)) {
        return;
      }
      for (var i = 0, len = e.clipboardData.items.length; i < len; i++) {
        var item = e.clipboardData.items[i];

        if (item.kind === 'string' && item.type === 'text/plain') {
          item.getAsString(function(str) {
            _this.insertHtmlAtCaret(html2Escape(str));
          });
        } else if (item.kind === 'file') {
          this.$Message.warning('仅允许粘贴文本内容');
        }
      }
      return false;
    },
    validAnswer(type) {
      //校验填空区域
      if (type != 'blur') {
        return;
      }
      this.errorTip4 = '';
      let contentEle = document.getElementById('quesContent');
      let answersEle = contentEle.getElementsByClassName('quesBlank');
      if (!this.Trim(contentEle.innerText, ':g')) {
        this.errorTip4 = '题目名称不能为空';
        return;
      }
      if (answersEle.length == 0) {
        this.errorTip4 = '请插入填空区';
        return;
      }
      if (Array.from(answersEle).some((ele) => !this.Trim(ele.value, ':g'))) {
        this.errorTip4 = '填空区内容不能为空';
        return;
      }
      if (Array.from(answersEle).some((ele) => this.Trim(ele.value).length > 64)) {
        this.errorTip4 = '填空区内容不能超过64个字符';
        return;
      }
      if (contentEle.innerText.length > 1000 || contentEle.innerText.length < 1) {
        this.errorTip4 = '题目名称长度为1-1000个字符';
      }
    },
    //在复杂公式的div contenteditable=true的位置获取焦点并插入内容
    insertHtmlAtCaret(content) {
      let sel, range, textContent;
      sel = window.getSelection();
      if (
        !content &&
        sel.focusNode.id != 'quesContent' &&
        sel.focusNode.parentElement.id != 'quesContent'
      ) {
        return;
      }
      range = sel.getRangeAt(0);
      range.deleteContents();
      if (window.getSelection) {
        // IE9 and non-IE
        if (sel.getRangeAt && sel.rangeCount) {
          let el = document.createElement('div');
          if (content) {
            el.innerHTML = content;
          } else {
            el.innerHTML = `<input class='quesBlank' maxlength="64" style='width:40px;padding:0px 5px;box-shadow:none;outline:none;border:none;border-bottom:1px solid rgb(168,166,200)'></input>`;
          }
          let frag = document.createDocumentFragment(),
            node,
            lastNode;
          while ((node = el.firstChild)) {
            lastNode = frag.appendChild(node);
          }
          range.insertNode(frag); // Preserve the selection
          if (lastNode) {
            range = range.cloneRange();
            range.setStartAfter(lastNode);
            range.collapse(true);
            sel.removeAllRanges();
            sel.addRange(range);
          }
        }
      } else if (document.selection && document.selection.type != 'Control') {
        // IE < 9
        document.selection.createRange().pasteHTML(html);
      }
      textContent = document.getElementById('quesContent').innerHTML; //这个也很重要。因为如果不写可能就会覆盖了原来内容替换成你添加的。或者是干脆不显示了。textContent是全局变量是你输入的内容。
      let contentEle = document.getElementById('quesContent');
      let answersEle = contentEle.getElementsByClassName('quesBlank');
      if (answersEle.length > 0) {
        this.disAddBlank = true;
      } else {
        this.disAddBlank = false;
      }
    },
    parseDescription(question) {
      if (!question.answers) {
        return;
      }
      let description;
      description = question.description.replace(
        /\{\{.*?\}\}/g,
        `<span class='quesBlank' disabled style='color:var(--main-color);width:40px;padding:0px 5px;outline:none;box-shadow:none;border:none;border-bottom:1px solid rgb(168,166,200);color:#2d8cf0'></span>`
      );
      let el = document.createElement('div');
      el.innerHTML = description;
      let answersEle = el.getElementsByClassName('quesBlank');
      Array.from(answersEle).forEach((ele, index) => {
        answersEle[index].innerHTML = question.answers[index].explanation;
      });
      return el.innerHTML;
    },
    //导入导出
    //导入客观题
    handleFormatError() {
      this.uploadList = [];
      this.$Message.warning('文件格式错误');
    },
    handleBeforeUpload(file) {
      this.uploadList = this.$refs.upload.fileList;
      return true;
    },
    handleProgress(event, file, fileList) {},
    getImageUrl(data) {
      this.uploadList = [];
      if (data.code == 0) {
        this.$Message.error(data.message);
      } else {
        let failData = data.data.fail || [];
        let successData = data.data.success || [];
        this.importResultData = {
          failData,
          successData
        };
        let allData = [...failData, ...successData];
        if (allData.length > 0) {
          this.showFailModal = true;
        }
        this.$Message.info('导入客观题完成');
        this.refreshObjQuesList();
      }
    },
    uploadError() {
      this.uploadList = [];
      this.$Message.error('导入客观题失败');
    },
    //导出客观题
    exportObjectiveQuestion() {
      let ids = this.selectQuestions.map((ques) => ques.id);
      if (ids.length == 0) {
        this.$Message.warning('请选择题目');
        return;
      }
      exportQuestions(ids)
        .then((data) => {
          if (!data.code) {
            const fileReader = new FileReader();
            fileReader.readAsDataURL(data);
            fileReader.onload = (e) => {
              const downloadElement = document.createElement('a');
              downloadElement.href = e.target.result;
              downloadElement.download = '客观题.xlsx';
              document.body.appendChild(downloadElement);
              downloadElement.click();
              document.body.removeChild(downloadElement); // 下载完成移除元素
              this.selectQuestions = [];
              this.handleCheckAllQuestion(false);
            };
            fileReader.onerror = () => {};
          } else {
            this.$Message.error('导出客观题失败');
          }
        })
        .catch((error) => {
          console.log(error);
          this.$Message.error('导出客观题失败!');
        });
    },
    //选择导出用户
    handleCheckAllQuestion(e) {
      this.selectAllQuestion = e;
      this.objectiveList.forEach((ques) => {
        this.checkSingleQuestion(e, ques);
      });
    },
    checkSingleQuestion(e, ques) {
      if (e && !this.selectQuestions.map((ques) => ques.id).includes(ques.id)) {
        this.selectQuestions.push(ques);
      } else if (!e && this.selectQuestions.map((ques) => ques.id).includes(ques.id)) {
        let index = this.selectQuestions.findIndex((item) => ques.id == item.id);
        this.selectQuestions.splice(index, 1);
      }
      this.$set(ques, '_checked', e);
      if (
        this.objectiveList.length > 0 &&
        this.objectiveList.every((ques) => ques._checked === true)
      ) {
        this.selectAllQuestion = true;
      } else {
        this.selectAllQuestion = false;
      }
    }
  }
};
</script>
<style scoped>
.objectiveQuestion-warp {
  background-color: var(--card-body-bgcolor);
  border-radius: 10px;
  height: 100%;
  display: flex;
  flex-direction: column;
}
#quesContent {
  outline: none;
  color: var(--select-color);
  border: 1px solid var(--select-border-color) ;
  font-size: 14px;
  padding-left: 8px;
  min-height: 60px;
  border-radius: 4px;
  padding-bottom: 10px;
  word-break: break-all;
}
#quesContent:hover {
  border: 1px solid var(--select-focus-border-color) ;
}

#quesContent span {
  text-decoration: underline;
  display: inline-block;
  min-width: 40px;
}

.quesBlank {
  text-decoration: underline;
  display: inline-block;
  min-width: 40px;
}

.page-content {
  flex:auto;
  /* margin-top: 20px;
		overflow-x: hidden;
		overflow-y: auto; */
  max-height: calc(100vh - 220px);
  width: 100%;
  font-size: 14px;
  overflow-x: hidden;
  overflow-y: auto;
  margin-top: 20px;
}

.content-wrap {
  font-size: 14px;
}

.page-content::-webkit-scrollbar {
  /*滚动条整体样式*/
  width: 8px;
  /*高宽分别对应横竖滚动条的尺寸*/
  height: 4px;
}

.page-content::-webkit-scrollbar-thumb {
  /*滚动条里面小方块样式*/
  border-radius: 5px;
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  background: rgba(209, 209, 209, 0.6);
}

.page-content::-webkit-scrollbar-track {
  /*滚动条里面轨道样式*/
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  border-radius: 5px;
  background: rgba(179, 179, 179, 0.1);
}

.questionclass {
  display: inline-block;
  width: calc(100% - 120px);
  margin-left: 120px;
  margin-bottom: 16px;
}

.project-item {
  width: 100%;
  border-radius: 4px;
  border: 2px solid rgb(231, 231, 241);
  padding: 10px 15px;
  margin-bottom: 15px;
}

.item-first-line {
  display: flex;
  justify-content: space-between;
}

.project-name-state {
  display: flex;
  justify-content: flex-start;
}

.project-name {
  font-size: 16px;
  font-weight: 600;
  width: 300px;
  display: flex;
}

.project-name > .name {
  flex: 1;
  margin-left: 4px;
  cursor: pointer;
  color: #1563C2 ;
  white-space: pre;
  text-overflow: ellipsis;
  overflow: hidden;
  word-break: break-all;
}

.project-status-text {
  font-weight: 600;
  font-size: 14px;
  margin-left: 10px;
  display: flex;
  justify-content: flex-start;
}

.btn-icon-wrap {
  display: flex;
  justify-content: flex-end;
}

.click-icon {
  cursor: pointer;
  height: 22px;
  margin-left: 20px;
}

.project-other-info {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 8px;
  color: rgba(51, 51, 51, 0.4);
  font-weight: bold;
}

.sendMsgContent {
  display: flex;
  justify-content: flex-start;
  margin-left: 15px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  word-break: break-all;
  width: calc(100vh - 750px);
}

.floatWrap {
  width: calc(100% - 224px);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  /* margin-top: -32px; */
  /* padding-top: 20px; */
  margin-left: 224px;
  margin-top: 20px;
}
.floatWrap > button,
.floatWrap > div,
.floatWrap > label {
  margin-bottom: 10px;
}
/* .downloadUrl {
  color: #a5a5c6;
} */
.downloadUrl ,
.downloadUrl:hover {
  color: var(--url-color);
}
</style>
